<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>往来单位</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="<%=basePath %>web/js/jquery.min.js"></script>
    <script src="<%=basePath %>web/js/jquery.easyui.min.js"></script>
    <script src="<%=basePath %>web/js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="<%=basePath %>web/themes/icon.css">
    <link rel="stylesheet" href="<%=basePath %>web/themes/default/easyui.css">
    <link rel="stylesheet" href="<%=basePath %>web/css/wu.css">

  </head>
  
 <script>
        var  selectIndex = -1;
        function hideTable(){
            $("#searchdiv").toggle();
        }
          function CompanydetailShow(code) {
          	var path=$("#path").val();
            parent.addTabs("查看往来单位",path+"company/getCompanydetailByCode?code="+code);
        }
          function CompanydetailUpdate(code) {
          	var path=$("#path").val();
            parent.addTabs("修改往来单位",path+"company/getCompanydetailByCodeUpdate?code="+code);
        }
        $(function(){
       $("#search_btn").click(function(){
	       var form=$("#form1");
  		 $("#productList").datagrid('load',serializeForm(form));
       });
        $("#reset_btn").click(function(){
             	$("#form1").form('reset');
             	$("#productList").datagrid('load',serializeForm);
             });
			//将表单序列化
			function serializeForm(form){
				var obj={};
			$.each(form.serializeArray(),function(index){
				  if(obj[this['name']]){
					obj[this['name']]=obj[this['name']]+','+this['value']
				 }else{
				   obj[this['name']]=this['value'];
				 }
			});
			return obj;
		}   	
			var path=$("#path").val();
            $("#productList").datagrid({
                url:path+'company/getCompany_Detiail',
                rownumbers:true,
                checkOnSelect:false,
                pageNumber:1,
                pageSize:8,
                pageList:[8,12,16,20],
                columns:[[
                    {field:'ck',checkbox:true},
                    {field:'code',title:'单位代码',width:150,
    					formatter:function(value,row,index){
                              return  "<a href='javascript:void(0)' onclick=\"CompanydetailShow('"+row.code+"')\" style='color:blue;text-decoration:underline'>"+row.code+"</a>"
                        }
                    },
                    {field:'name',title:'单位名称',width:200},
                    {field:'type',title:'类型',width:100,
                        formatter:function(value,row,index){
                            if(row.type==1){
                              return "客户";
                            }else if(row.type==2){
                            	return "供应商";
                            }else{
                            	return "客户/供应商"
                            }
                        }
                    },
                    {field:'telephone',title:'固定电话',width:130},
                    {field:'linkman',title:'联系人',width:80},
                    {field:'address',title:'地址',width:190},
                    {field:'state',title:'显示状态',width:70,
                        formatter:function(value,row,index){
                            if(row.state==1){
                              return "显示";
                            }
                            return "隐藏";
                        }
                    },
                    {field:'admin',title:'操作员',width:70,
	                    formatter:function(value,row,index){
	                    	return "${user.userName}";
	                    }
                    },
                    {field:'opt',title:'操作',width:109,formatter:function (value,row,index) {
                            var context= "<a href='javascript:void(0)' onclick=\"CompanydetailUpdate('"+row.code+"')\" style='color:blue;text-decoration:underline'>修改</a>&nbsp&nbsp"+
                                "<a href='javascript:void()'style='color:blue;text-decoration:underline;'  onclick=\"onedel('"+row.code+"')\">删除</a>&nbsp;"
                            return context;
                        }}

                ]],
                toolbar:'#wu_toolbar',
                 onClickRow:function(index,row){
                	$(this).datagrid("unselectRow",index);
                },
                pagination:true//向后台传递参数page 和rows
            })
        })
	   function onedel(code){
	   		var path=$("#path").val();
		   	$.messager.confirm('确认提醒','您确认想要删除记录吗？',function(r){    
	   			if (r){    
	   				 $.ajax({
							type:"get",//请求类型
							url:path+"company/delCompany_detail", 
							dataType:"json",//ajax接口（请求url）返回的数据类型
							data:{'code':code},
							success:function(data){//data：返回数据（json对象）
								 if(data.flag=="y"){
									     $.messager.alert('我的消息','编号'+code+'删除成功!','info');
									     $('#productList').datagrid('reload');
								  }else{
									   	 $.messager.alert('我的消息','编号'+code+'删除失败!','error');
								  }
							}
					   });
		   			}  
			 });  
	   }   
        function detail(id) {
            $.messager.alert("信息","查看"+id+"产品详情");
        }
        function addProduct() {
            parent.addTabs("添加往来单位","goods/addCompanyDetiail.jsp");
        }
        function reload(){
        	location.reload();
        }
    </script>

</head>
<body>
<div id="wu_toolbar">
    <div class="wu_toolbar_button">
        <a  href="javascript:void(0)" onclick="hideTable()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" plain="true">查询</a>|
        <a  href="javascript:void(0)" onclick="addProduct()" class="easyui-linkbutton" data-options="iconCls:'icon-add'" plain="true">添加</a>|
        <a  href="javascript:void(0)" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-page-refresh'" plain="true">刷新</a>|
        <a  href="javascript:void(0)" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-communication'" plain="true">导出excal</a>
    </div>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1">

            <table width="100%" border="0" cellspacing="0" style="background-color:#c9dfff;font-size: 14px " >
                <tbody><tr>
                    <td width="70"><b>检索条件:</b></td>
                    <td width="60" align="right">编号:</td>
                    <td width="80" align="left"><input id="code" name="code" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="60" align="right">联系人:</td>
                    <td width="80" align="left"><input id="linkman" name="linkman" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="60" align="right">地址:</td>
                    <td width="80" align="left"><input id="address" name="address" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="60" align="right">名称:</td>
                    <td width="80" align="left"><input id="name" name="name" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="70" align="right">单位类别:</td>
                    <td width="80" align="left">
                    	<select name="type" id="type" class="easyui-combobox" style="width:120px;height:30px" panelHeight="150px">
                    		<option value="0" selected="selected">--请选择--</option>
                    		<option value="1">客户</option>
                    		<option value="2">供应商</option>
                    		<option value="3">客户/供应商</option>
                    	</select>
                    </td>
                    <td width="72">
                        <a id="search_btn"  href="javascript:void(0)" class="easyui-linkbutton"  data-options="iconCls:'icon-search'">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>


                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
            <input type="hidden" id="path" value="<%=basePath%>">
        </form>
    </div>
</div>
<div id="productList" class="easyui-datagrid">


</div>
<div id="show" style="margin-top:10px;display:none">
  <div id="detailed" style="margin-bottom:10px">
    
  </div>
  <div id="partList" class="easyui-datagrid">
     
  </div>
</div>
</body>
</html>
